using System;
using NHibernate.Cfg;

namespace Web.Extensions
{
	public abstract class DatabaseConfigurationBase : IDatabaseConfiguration
	{
		protected DatabaseConfigurationBase()
		{
			lazyConfiguration = new Lazy<Configuration>(() =>
			{
				var cfg = BuildConfiguration();
				ProcessConfiguration(cfg);
				return cfg;
			});
		}

		protected virtual void ProcessConfiguration(Configuration cfg) { }

		public abstract void CreateNew();

		protected abstract Configuration BuildConfiguration();

		public Configuration DatabaseConfiguration { get { return lazyConfiguration.Value; } }

		readonly Lazy<Configuration> lazyConfiguration;

	}
}